<template>
  <div class="tuanbox">
    <div class="nav">
      <div class="nav_box">
        <router-link to="/home/team-t" class="router-link-active">团队风采馆</router-link>
        <el-icon color="#999">
          <DArrowRight />
        </el-icon>
        <router-link to="/home/team-t" class="router-link-active">支部风采</router-link>
      </div>
    </div>
    <div class="couter">
      <div class="left">
        <el-col :span="24">
          <el-menu class="el-menu-vertical-demo" router="true" v-for="(item, index) in listdata" :key="index"
            @click="pavent(item)" :default-openeds="defaultOpenIndex">
            <el-sub-menu :index="index" :class="acti == item.id ? 'activeitem' : ''">
              <template #title>
                <img src="@/assets/minlogo.png" alt="" class="mmm" />
                <span style="color: red;">{{ item.name }} </span>
              </template>
              <div class="itemmm" v-for="(ite, ind) in item.children" :key="ind" @click="child(ite)"
                :class="acti == ite.id ? 'activeitem' : ''">
                {{ ite.name }}
              </div>
            </el-sub-menu>
          </el-menu>
        </el-col>
      </div>
      <div class="right">
        <div class="onebox">
          <div v-for="(item, index) in dynamic" :key="index" class="mou">
            <div class="cen_time">
              <div class="daymonth">
                <span class="daytian">{{ item.day }}</span>
                <span class="month"> {{ item.month }}月</span>
              </div>
              <div class="shijians">
                {{ item.time }}
              </div>
            </div>
            <div class="centertext" @click="detail(item.id)">
              <div>
                <div v-if="ad === index" class="cen_textss">
                  {{ item.content }}
                </div>
                <div class="cen_text" v-else>
                  {{ item.content }}
                </div>
                <div class="kai" v-show="item.content.length > 115">
                  <div @click.stop="zhankai(index)">{{ ad === index ? (sub = '收起') : (sub = '展开') }}</div>
                </div>
              </div>
              <div style="display: flex">
                <div class="image">
                  <div v-for="(ite, ind) in item.images.slice(0, 4)" :key="ind">
                    <img :src="ite" alt="" />
                  </div>
                </div>
                <div style="
                    display: flex;
                    align-items: flex-end;
                    margin-left: 2px;
                    color: #767676;
                  " v-if="item.images.length > 4">
                  共{{ item.images.length }}张
                </div>
              </div>
              <div class="m_le">
                <div @click.stop="like(item.id)" style="cursor: pointer">
                  <div class="zan" v-if="item.is_like == 0">
                    <img src="@/assets/nozan.png" alt="" />
                  </div>
                  <div class="zan" v-else>
                    <img src="@/assets/zan.png" alt="" />
                  </div>
                </div>
                <div class="le">{{ item.like }}</div>
              </div>
            </div>
          </div>
          <div class="con_bom" v-if="total > 0">
            <div class="cc">共{{ total }}条</div>
            <el-pagination v-model:page-size="pageSize" background layout="prev, pager, next" :total="total"
              @next-click="nextclick" @prev-click="prevclick" @change="change1" />
          </div>
          <div class="rq" v-show="tabs">
            <img src="@/image/容器.svg" alt="" />
            <div>暂无信息</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useRouter } from 'vue-router'
import { onMounted, ref, reactive } from 'vue'
import { teamdept, deptList, lists, listsdetail, likes } from '@/api/team'
const defaultOpenIndex = ref([0]);
let listdata: any = ref<any>()
let data: any = ref({
  range: 2,
  dept_id: 10,
  page: 1,
  page_size: 3
})
let total = ref(0)
let pag = ref()
const diyi = async () => {
  await lists(data.value).then(res => {
    pag.value = res.data.data
    dynamic.value = res.data.data.data
    total.value = res.data.data.total
    console.log(pag.value, 'imagessss')
  })
  if (dynamic.value == !{}) {
    tabs.value = true
  } else {
    tabs.value = false
  }
}
diyi()

const isExpanded = ref(false)
const myimg: any = ref<any>()
const list = async () => {
  await teamdept().then(res => {
    listdata.value = res.data.data[0].children
    // console.log(listdata.value.id, 'list')
  })
}
list()

let tabs = ref(true)
let dynamic: any = ref()
const myitem = ref(0)
let acti: any = ref(10)
const pavent = async (item: any) => {
  data.value.page = 1
  myimg.value = item.id
  if (myimg.value == item.id) {
    // zk.value = !zk.value
  }
  if (item.children == !{}) {
    // 动态数据
    acti.value = item.id
    data.value.dept_id = item.id
    await lists(data.value).then(res => {
      dynamic.value = res.data.data.data
      total.value = res.data.data.total
      console.log(dynamic.value)
    })
    if (dynamic.value == !{}) {
      tabs.value = true
    } else {
      tabs.value = false
    }
  }
}


const child = async (ev: any) => {
  data.value.page = 1
  // 点击孩子出现动态数据
  myitem.value = ev
  acti.value = ev.id
  data.value.dept_id = ev.id
  await lists(data.value).then(res => {
    dynamic.value = res.data.data.data
    total.value = res.data.data.total
    console.log(dynamic.value)
  })
  if (dynamic.value == !{}) {
    tabs.value = true
  } else {
    tabs.value = false
  }
  xsdetail.value = false
}
const xsdetail = ref(false)
const detail = async (e: any) => {
  const url = `/pc/home/team-t/detail?e=${encodeURIComponent(e)}`
  window.open(url, '_blank')
}
let pageSize = ref(3)
const nextclick = () => {
  data.value.page++
  console.log(data.value.page, 'eee')
  diyi()
}
const prevclick = () => {
  data.value.page--
  console.log(data.value.page, 'eee')
  diyi()
}
const change1 = (e: any) => {
  console.log(e, 'eee')
  data.value.page = e
  diyi()
}
const like = (id: any) => {
  likes({ id: id }).then(res => {
    console.log(res, 'dianzan')
    diyi()
  })
}
// onMounted(() => {
// })
let sub = ref('展开')
let ad = ref(null)
const zhankai = (index: any) => {
  if (ad.value === index) {
    ad.value = null; // 点击已展开的内容时收起
  } else {
    ad.value = index; // 点击未展开的内容时展开
  }
}
</script>

<style lang="scss" scoped>
.kong {
  width: 100%;
  height: 100%;
  background: #fff;
}

.card_tou {
  display: flex;
  width: 90%;
  height: 100px;
  border-bottom: 2px solid #ccc;
  margin-left: 5%;

  img {
    width: 100%;
    height: 70px;
    margin: 10px;
    border-radius: 50%;
  }

  .card_name {
    flex: 1;
    line-height: 40px;
    margin-left: 10px;

    h2 {
      span {
        padding: 5px;
        border-bottom: #767676 2px solid;
      }
    }

    h3 {
      color: #e02020;
    }
  }
}

.card_cent {
  width: 392px;
  height: 164px;
  // margin-top: 10px !important;
  border-radius: 2px;
  margin: 10px;
  background: #fff;
  float: left;
}

.mmm {
  width: 18px;
  height: 18px;
  margin-right: 3px;
}

.el-menu-vertical-demo {
  span {
    color: red;
  }
}

.tuanbox {
  width: 100%;
  background: #f0f0f0;
}

.couter {
  width: 100%;
  display: flex;
  height: 1200px;

  .left {
    width: 232px;
    // height: 100%;
    background: #fff;
    margin-left: 20px;
    margin-top: 15px;
  }

  .right {
    width: 816px;
    background: #fff;
    margin-left: 20px;
    margin-top: 15px;
    height: 1185px;
    position: relative;
  }
}

.nav {
  height: 54px;
  line-height: 54px;
  background-color: #fff;
  margin-bottom: 16px;

  .nav_box {
    margin-left: 44px;
    font-size: 16px;
    color: #999999;

    .router-link-active {
      font-size: 16px;
      color: #999999 !important;
      text-decoration: none;
    }

    .el-icon {
      margin: 15px 10px 0 10px;
    }
  }
}

.image {
  // margin-left: 15px;
  // float: left;
  display: flex;
  flex-wrap: wrap;

  img {
    margin-top: 10px;
    margin-left: 10px;
    width: 140px;
    height: 140px;
    border-radius: 10px;
  }
}

.cen_text {
  width: 100%;
  height: 100px;
  display: -webkit-box;
  /* 将元素视为块级盒子 */
  -webkit-line-clamp: 3;
  /* 控制显示的行数 */
  -webkit-box-orient: vertical;
  /* 设置文本排列方向为垂直 */
  overflow: hidden;
  /* 超出部分隐藏 */
  text-overflow: ellipsis;
  /* 超出部分用省略号表示 */
  font-size: 18px;
  line-height: 35px;
  word-wrap: break-word;
  word-break: break-all;
}

.img {
  .img_bom {
    display: flex;
    align-items: center;
    margin-top: 19px;

    .my_img {
      position: relative;
      width: 89px;
      height: 89px;
      margin-right: 8px;
      border-radius: 8px;

      .mss {
        position: absolute;
        width: 89px;
        height: 89px;
        border-radius: 8px;
        background: rgba(26, 26, 26, 0.7);
        z-index: 99;
        top: 0;
        cursor: pointer;
      }
    }

    img {
      margin-right: 8px;
      width: 89px;
      height: 89px;
      border-radius: 8px;
    }

    .el-icon {
      font-size: 30px;
      color: #9e9e9e;
      cursor: pointer;
    }
  }

  .img_top {
    img {
      width: 640px;
      height: 445px;
    }
  }
}

.zan {
  // margin-top: 40px;
  height: 40px;
  // border-bottom: 2px solid #ccc;
  // text-align: center;
  line-height: 40px;
  display: flex;
  justify-content: center;

  img {
    cursor: pointer;
    width: 25px;
    height: 25px;
  }
}

.cen_time {
  width: 15%;
  height: 200px;
  text-align: right;
  margin-right: 20px;
}

.cen_textss {
  width: 100%;
  font-size: 18px;
  line-height: 35px;
  word-wrap: break-word;
  word-break: break-all;
  // line-height: 45px;
}

.onebox {
  width: 100%;
  height: 1120px;
  // display: flex;
  overflow: auto;
  background: #fff;

  .mou {
    display: flex;
    border-bottom: 1px solid #e5e5e5;
    // margin-top: 30px;
    padding: 30px 10px;
  }
}

.onebox::-webkit-scrollbar {
  display: none;
}

.oneboxs {
  width: 100%;
  // height: 1200px;
  display: flex;
  background: #fff;
}

.centertext {
  width: 100%;
  cursor: pointer;
  // margin-left: 20px;
  // border-bottom: 2px solid #ccc;
}

.centertexts {
  width: 80%;
  margin-left: 20px;
}

.m_le {
  margin-top: 20px;
  margin-left: 200px;
  display: flex;
  margin-bottom: 20px;
  font-size: 20px;

  .le {
    margin-left: 5px;
  }
}

.tjindex {
  text-align: center;
  margin: 20px 0;
  cursor: pointer;
}

// @media (min-width: 2160px) {
//     .tuanbox {
//         width: 100%;
//         margin: 0 auto;
//         // background-color: #f0f0f0;
//     }
// }

// @media (max-width: 2159px) {
.tuanbox {
  width: 1080px;
  margin: 0 auto;
  // background-color: #f0f0f0;
}

// }

.con_bom {
  position: absolute;
  bottom: 30px;
  left: 50%;
  display: flex;
  // margin-left: -100px;
  transform: translateX(-50%);

  .cc {
    width: 100px;
    margin-top: 8px;
    text-align: center;
  }
}

.rq {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  // margin-top: 100px;
  width: 100%;
  height: 50%;
  // background: olive;

  img {
    width: 228px;
    height: 226px;
  }
}

.claer {
  clear: both;
}

.title {
  display: flex;
  padding-top: 22px;

  .t_nav {
    font-size: 16px;
    font-weight: 600;
    color: #e02020;
  }

  .t_nav1 {
    font-size: 16px;
    font-weight: 600;
    color: #767676;
  }

  .tet {
    width: 180px;
    // text-align: center;
    // margin-bottom: 11px;
  }
}

.aaa {
  // height: 50px;
  text-align: center;
  padding: 10px 0;
}

.t_item {
  margin: 4px auto;
  width: 216px;
  height: 36px;
  line-height: 36px;
  color: #e02020;
  font-size: 14px;
  border-radius: 2px;
  background: rgba(224, 32, 32, 0.1);
  cursor: pointer;

  .tet {
    margin-left: 44px;
  }
}

.t_item1 {
  margin: 4px auto;
  width: 216px;
  height: 36px;
  line-height: 36px;
  color: rgba(0, 0, 0, 0.6);
  font-size: 14px;
  cursor: pointer;

  .tet {
    margin-left: 44px;
  }
}

.itemmm {
  padding: 10px 0px 10px 40px;
  cursor: pointer;
}

.activeitem {
  background: #faa7a74b;
  color: #e02020;
}

.daymonth {
  .daytian {
    font-size: 18px;
    margin-right: 10px;
  }

  .month {
    font-size: 13px;
  }
}

.shijians {
  margin-top: 10%;
  color: #ccc;
}

.eqwer {
  .el-sub-menu .el-sub-menu__icon-arrow {
    display: none !important;
  }
}

.kai {

  display: flex;
  justify-content: end;
  cursor: pointer;
  color: red;

  div {
    width: 50px;
    // background: olive;
  }
}
</style>
